package com.example.homemodule.adapter;

import android.annotation.SuppressLint;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.CircleCrop;
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.example.homemodule.model.bean.HomepageEntity;
import com.example.homemodule.R;

import java.util.List;

public class HomeDoctorAdapter extends BaseMultiItemQuickAdapter<HomepageEntity.DataBean.DoctorListBean, BaseViewHolder> {


    /**
     * Same as QuickAdapter#QuickAdapter(Context,int) but with
     * some initialization data.
     *
     * @param data A new list is created out of this one to avoid mutable list
     */

    public static boolean isEnable = false;
    private static final String AVATAR_FEMALE = "https://cdn.yilijk.com/images/vbp/patientimg/female.png";
    private static final String AVATAR_MALE = "https://cdn.yilijk.com/images/vbp/patientimg/male.png";


    public HomeDoctorAdapter(List<HomepageEntity.DataBean.DoctorListBean> data) {
        super(data);

        addItemType(0, R.layout.item_home_doctor);
        addItemType(1, R.layout.item_home_doctor1);
    }

    @SuppressLint("ResourceAsColor")
    @Override
    protected void convert(BaseViewHolder helper, HomepageEntity.DataBean.DoctorListBean item) {
        boolean isBzShow = item.isBzShow();
//        boolean isBzShow = helper.getAdapterPosition() %3 == 0;
        View cardBg = helper.getView(R.id.card_bg);
        View bzAvatar = helper.getView(R.id.bz_avatar);
        if (isBzShow) {
            cardBg.setBackgroundResource(R.mipmap.bg_doctor_card_bz);
            bzAvatar.setVisibility(View.VISIBLE);
        } else {
            cardBg.setBackgroundResource(R.mipmap.bg_doctor_card);
            bzAvatar.setVisibility(View.INVISIBLE);
        }
        helper.addOnClickListener(R.id.cusult_doctor);
        helper.addOnClickListener(R.id.fast_track);
        helper.addOnClickListener(R.id.card_more);
//        helper.addOnClickListener(R.id.textCharges);
//        helper.addOnClickListener(R.id.phoneCharges);
        helper.setVisible(R.id.textCharges, item.isHasTextCharges());
        helper.setVisible(R.id.phoneCharges, item.isHasPhoneCharges());
        helper.setVisible(R.id.videoCharges, item.isHasVideoCharges());
        helper.setVisible(R.id.hospitalChange, item.isHasReferral());
        helper.setVisible(R.id.xxxrCharges,item.isHeartToward());
        if (TextUtils.isEmpty(item.getAvatar())) {
            if (item.getGender() != null && "M".equals(item.getGender().getKey())) {
                Glide.with(mContext).load(AVATAR_MALE).transform(new CenterCrop(), new CircleCrop()).into((ImageView) helper.getView(R.id.homedoctor_avator));
            } else {
                Glide.with(mContext).load(AVATAR_FEMALE).transform(new CenterCrop(), new CircleCrop()).into((ImageView) helper.getView(R.id.homedoctor_avator));
            }
        } else {
            Glide.with(mContext).load(item.getAvatar()).transform(new CenterCrop(), new CircleCrop()).into((ImageView) helper.getView(R.id.homedoctor_avator));
        }
//        helper.setText(R.id.homedoctor_name, item.getName()+" "+item.getJobTitle().getDesc()+" "+item.getDepartment().getName());

//        SpannableString spannableString = new SpannableString(item.getName() + " " + item.getJobTitle().getDesc() + " " + item.getDepartment().getName());
//        spannableString.setSpan(new RelativeSizeSpan(1.5f), 0, item.getName().length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
//        helper.setText(R.id.homedoctor_name, spannableString);
        helper.setText(R.id.homedoctor_name, item.getName());
        helper.setTextColor(R.id.homedoctor_name,isBzShow?mContext.getResources().getColor(R.color.color_A46E1A):mContext.getResources().getColor(R.color.color_333333));
        helper.setText(R.id.homedoctor_title, item.getJobTitle() != null ? item.getJobTitle().getDesc() : "");
        helper.setTextColor(R.id.homedoctor_title,isBzShow?mContext.getResources().getColor(R.color.color_A46E1A):mContext.getResources().getColor(R.color.color_666666));

//        SpannableString spannableString = new SpannableString(item.getName() + " " + item.getJobTitle().getDesc() + " " + item.getDepartment().getName());
//        spannableString.setSpan(new RelativeSizeSpan(1.5f), 0, item.getName().length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
//        spannableString.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, item.getName().length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
//        helper.setText(R.id.homedoctor_name, spannableString);

//        helper.setText(R.id.homedoctor_jobtitledesc, item.getJobTitle().getDesc());
//        helper.setText(R.id.homedoctor_departmentid, item.getDepartment().getName());
        helper.setText(R.id.homedoctor_hospitalname, item.getHospital().getName() + " " + item.getDepartment().getName());
        helper.setTextColor(R.id.homedoctor_hospitalname,isBzShow?mContext.getResources().getColor(R.color.color_A46E1A):mContext.getResources().getColor(R.color.color_666666));

        TextView textView = helper.getView(R.id.cusult_doctor);
//        if (!isEnable && !item.isBeta()) {
//        if (!item.isBeta()) {
//            textView.setText("暂不接诊");
//            textView.setBackgroundResource(R.drawable.btn_un_enable);
////            textView.setTextColor(Color.parseColor("#AD156B"));
//        } else {
//            if (item.isChargeEnable() && item.isHasPhoneCharges()) {
//                textView.setText("咨询医生");
//                textView.setBackgroundResource(R.drawable.btn_enable);
////            textView.setTextColor(Color.parseColor("#AD156B"));
//            } else if (item.isChargeEnable()){
//                textView.setText("暂不接诊");
//                textView.setBackgroundResource(R.drawable.btn_un_enable);
////            textView.setTextColor(Color.parseColor("#B3B3B3"));
//            }
//        }

        if (item.isChargeEnable()) {
            helper.setVisible(R.id.notify_doctor_open_charge,false);
            textView.setText("咨询医生");
            if (isBzShow) {
                textView.setBackgroundResource(R.drawable.btn_enable);
            } else {
                textView.setBackgroundResource(R.drawable.btn_normal_enable);
            }
        } else {
            textView.setText("暂不接诊");
            if (isBzShow) {
                textView.setBackgroundResource(R.drawable.btn_un_enable);
            } else {
                textView.setBackgroundResource(R.drawable.btn_normal_un_enable);
            }
            helper.setVisible(R.id.notify_doctor_open_charge,true);
            if (item.isNotifyOpenCharge()){
                helper.setImageResource(R.id.notify_doctor_open_charge,R.mipmap.img_remind_open);
            }else{
                helper.setImageResource(R.id.notify_doctor_open_charge,R.mipmap.img_remind_invite);
            }

        }

        TextView fastTrackTv = helper.getView(R.id.fast_track);
        if (item.isHasETP()) {
            if (isBzShow) {
                fastTrackTv.setBackgroundResource(R.drawable.btn_enable);
            } else {
                fastTrackTv.setBackgroundResource(R.drawable.btn_normal_enable);
            }
        } else {
            if (isBzShow) {
                fastTrackTv.setBackgroundResource(R.drawable.btn_un_enable);
            } else {
                fastTrackTv.setBackgroundResource(R.drawable.btn_normal_un_enable);
            }
        }
    }

    public void setEnable(boolean enable) {
        isEnable = enable;
    }
}
